<!-- 文件所有权归北京优博泰克 -->
<template>
    <div class="vehicleTestLibrary" v-loading="loading">
        <!-- 列表展示组件 -->
        <dy-table :elTable_Options="elTable_Options" @handleClick="handleClick" @bottonHandle="bottonHandle"
            ref="table" />
    </div>
</template>
<script setup>
import { ref, nextTick, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useCach } from '@/store/cach'
import commonV from '@/common'

onMounted(() => {
    gettabledata()
})

const router = useRouter()
let pageCach = useCach()

let allConfigList = [
    {
        label: "case包编号",
        prop: "case_package_no",
        columType: 'linkTo',
        width: 170
    },
    {
        label: "case包名称",
        prop: "package_name",
        columType: 'text'
    }, {
        label: "创建人",
        prop: "create_by",
        columType: 'arrayKey',
        keyName: "real_name"
    },
    {
        label: "包含case数量",
        prop: "case_num",
        columType: 'text'
    }, {
        label: "模拟收入合计",
        prop: "total_money",
        columType: 'text'
    }, {
        label: "任务描述",
        prop: "description",
        columType: 'text'
    },
    {
        label: "试验类型",
        prop: "test_type",
        columType: 'select',
        commonVarrName: 'vehicleTestPackage_test_type',
    }
]

// 响应式数据
let loading = ref(false)

// 表格配置
let elTable_Options = ref({
    pagename: '整车试验CASE包',
    selection: false,
    pagetittype: 'standardcase_pagecountcarpage',
    allConfigList: allConfigList,
    eltableArr: allConfigList, //表头数据
    getwayname: "vehiclecasepackage",
    getdetailwayname: "",
    uid: 'standardcase_pagecountcarpage',
    opbutton: [
        {
            label: '新增标准试验CASE包',
            dealway: 'createdata',
            icon: 'Plus',
            keyV: "add",
            type: "primary",
            disabled: false
        },
        {
            label: "批量删除",
            dealway: "asysdeleterow",
            icon: 'Delete',
            type: "danger",
            keyV: "deleteT",
            plain: true,
            disabled: false
        }
    ],
    searchList: [
        {
            label: "搜索case包名称",
            key: "package_name",
            searchtype: 'input',
            width: "240"
        },
        {
            label: "case包编号",
            key: "case_package_no",
            searchtype: 'input'
        },
        {
            label: "创建人",
            key: "create_by_name",
            searchtype: 'input'
        },
        {
            label: "试验类型",
            key: "test_type",
            searchtype: 'select',
            options: commonV.statusOption.vehicleTestPackage_test_type
        }
    ]
})

// 模板引用
let table = ref(null)

//获取数据
let gettabledata = () => {
    if (pageCach.tableInfo && pageCach.tableInfo.uid == elTable_Options.uid) {
        table.value.setSearchData(pageCach.tableInfo.searchParams)
        nextTick(() => {
            table.value.getTableData(pageCach.tableInfo)
        })
        return
    }
    nextTick(() => {
        table.value.getTableData()
    })
}

let handleClick = (row, index) => {
    //查看
    if (index == 3) {
        //记录当前页面信息
        pageCach.changeTableInfo({
            //p
            p: table.value.tableIntance.state.p,
            //pageSize
            size: table.value.tableIntance.state.size,
            //搜索参数
            searchParams: table.value.searchParams,
            //唯一标识
            uid: elTable_Options.uid
        })

        router.push({
            path: `/syStandardLib/vehicleTestPackage/view/${row.id}`
        })
    }
}

let bottonHandle = (wayname) => {
    if (wayname == 'createdata') {
        createdata()
        return
    }

    if (wayname == 'asysdeleterow') {
        asysdeleterow()
        return
    }
}


let asysdeleterow = async () => {
    let selectArr = table.value.getTableSelection()
    if (!selectArr.length) {
        ElMessage({
            message: '请选择删除项',
            type: 'warning'
        })
        return
    }

    let ids = selectArr.map(it => it.id)
    ElMessageBox.confirm(`确认删除选中${ids.length}项?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
    }).then(async () => {
        state.loading = true
        let res = await api.changeaxiosdata('deletevehiclecasepackage', 'post', ids)
        if (res) {
            ElMessage({
                message: '操作成功!',
                type: 'success'
            })
            getData()
        }
        state.loading = false
    }).catch(() => { })
}

let createdata = () => {
    router.push('/syStandardLib/vehicleTestPackage/create')
}
</script>
<style scoped></style>
